﻿using Microsoft.AspNetCore.Mvc;
using Project.Ycm20250401.Net.Models;
using Project.Ycm20250401.Service._20250408;

namespace Project.Ycm20250401.Net.Controllers
{
    [ApiController]
    [Route("api/payments")]
    public class PaymentController : ControllerBase
    {
        private readonly IEnumerable<IPaymentProvider> _paymentProviders;

        public PaymentController(IEnumerable<IPaymentProvider> paymentProviders)
        {
            _paymentProviders = paymentProviders;
        }

        [HttpPost("{provider}")]
        public async Task<IActionResult> Pay(string provider, [FromBody] PaymentRequest request)
        {
            var paymentService = _paymentProviders.FirstOrDefault(p => p.GetType().Name.StartsWith(provider));
            if (paymentService == null) return BadRequest("Unsupported payment provider");

            var result = await paymentService.PayAsync(request.Amount, request.OrderId, request.Metadata);
            return Ok(result);
        }
    }
   
}
